home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10745 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. From: _GOYRA_@msn.com (David Byrden)
  2. Subject: RE: [Q] namespace #1
  3. Date: 9 Mar 96 22:14:19 -0800
  4. References: <4hf81b$aov@crl.crl.com>
  5. Message-ID: <00001a81+0000abf7@msn.com>
  6. Path: news.msn.com!msn.com
  7. Newsgroups: comp.lang.c++
  8. Organization: The Microsoft Network (msn.com)
  9.  
  10.  
  11. <<<<start quote<<<<<<<<<<<<<<<
  12.  
  13. namespace foo
  14. {
  15.     int Value = 43;
  16. };
  17.  
  18. void main()
  19. {
  20.     int Value = 65;
  21.     using namespace foo;
  22.     cout << Value << endl;
  23. }
  24.  
  25. // QUESTIONS:
  26. // 1) Is this a valid program
  27. // 2) If so what is the expected output, if not what is the error
  28. // 3) What would be the result of using a using declaration instead
  29. //    instead of a using directive
  30. //
  31. // NOTES:
  32. // 1) The Microsoft VC++ 4.0 compiler complains that Value is an
  33. //    ambiguous symbol. Is this correct?
  34.  
  35. >>>>>>>>>>>> end quote >>>>>>>>>>>>>>>>
  36.  
  37.  
  38.     Dick;
  39.  
  40.     Names introduced by a using directive are found as if located in the 
  41. smallest namespace which contains both the using-directive and the 
  42. nominated namespace, i.e. they can be hidden by more-local names.
  43.  
  44.     The code is correct and Microsoft are wrong. The expected output is 65.
  45.  
  46.     A using declaration is subject to the normal rules for declarations, 
  47. and therefore you would be declaring two Values in the same block, 
  48. which is not allowed.
  49.  
  50.  
  51.                         David
  52.